package com.hy.video.monitor.service.email;

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @program: mrcos
 * @description Email 发送服务SMTP 方式
 * @author: 张三少
 * @create: 2022-04-26 16:31
 **/
@ConditionalOnProperty(prefix = "mooc.email-provider", name = "name", havingValue = "smtp")
@RequiredArgsConstructor
@Service
public class EmailServiceSmtpImpl implements EmailService{

    private final JavaMailSender emailSender;

    @Override
    public void send(String email, String msg) {
        val message = new SimpleMailMessage();
        message.setTo(email);
        message.setFrom("zhang-ning-qiang@163.com");
        message.setSubject("实战 Spring Security 登录验证码");
        message.setText("验证码为:" + msg);
        emailSender.send(message);
    }
}
